package com.xyzwps.paimon.furina.common.value

import com.xyzwps.paimon.furina.common.AppErrorCode
import com.xyzwps.paimon.furina.common.AppException
import java.util.regex.Pattern

data class DedupKey(override val value: String) : StringValue {
    init {
        if (!DEDUP_KEY_PATTERN.matcher(value).matches()) {
            throw AppException(
                AppErrorCode.REQUEST_ARG_FORMAT_INVALID,
                "DedupKey 格式不正确"
            )
        }
    }

    companion object {
        const val MAX_LEN = 60
        val DEDUP_KEY_PATTERN: Pattern = Pattern.compile("^[a-zA-Z0-9_-]{16,$MAX_LEN}$")
    }
}